#region README

/*
 * README
 * 
 * Current Thread User : GUOCOLAND\wangyucai
 * Machine Name : GLCHQWYCWINW7
 * Visual Studio : Microsoft Visual Studio 2010 Ultimate Edition
 * Create Time : 2015-02-11 13:43:45
 * Common Language Runtime : 4.0.30319.18444
 * Minimum .Net Framework Version : 4.0
 * 
 * SourcePro Studio 2015
 * Project Url : https://github.com/SourceproStudio/CodeTemplates
 * Home Page Url : https://github.com/SourceproStudio
 * E-mail Address : MasterDuner@yeah.net or Yucai.Wang-Public@outlook.com
 * QQ : 180261899
 */

#endregion

using System;
using System.Windows.Markup;
using System.Windows.Media;

namespace Dearcodes.Examples.Wpf.XamlExtensions
{
    /// <summary>
    /// <para>
    /// 用于绘制Grid背景色。
    /// </para>
    /// <para>
    /// Namespace : <see cref="Dearcodes.Examples.Wpf.XamlExtensions"/>
    /// </para>
    /// <para>
    /// Type : <see cref="GridBackgroundColorBrush"/>
    /// </para>
    /// <para>
    /// The minimum .Net Framework version requirements : 4.0
    /// </para>
    /// <para>
    /// Can not inherit from <see cref="GridBackgroundColorBrush"/> !
    /// </para>
    /// </summary>
    /// <seealso cref="Dearcodes.Examples.Wpf.XamlExtensions"/>
    /// <remarks>
    /// Can not inherit from <see cref="GridBackgroundColorBrush"/> !
    /// </remarks>
    public sealed class GridBackgroundColorBrush : MarkupExtension
    {
        private string _backgroundColor;

        #region BackgroundColor
        /// <summary>
        /// 设置或获取Grid背景颜色值。
        /// </summary>
        public string BackgroundColor
        {
            get { return _backgroundColor; }
            set { _backgroundColor = value; }
        }
        #endregion

        #region GridBackgroundColorBrush Constructors

        /// <summary>
        /// <para>
        /// 用于初始化一个<see cref="GridBackgroundColorBrush" />对象实例。
        /// </para>
        /// </summary>
        /// <param name="backColor">背景色值。</param>
        public GridBackgroundColorBrush(string backColor)
        {
            this.BackgroundColor = backColor;
        }

        /// <summary>
        /// <para>
        /// 用于初始化一个<see cref="GridBackgroundColorBrush" />对象实例。
        /// </para>
        /// </summary>
        public GridBackgroundColorBrush()
            : this("#000000")
        { }

        #endregion

        #region GetBackgroundColorBrushInstance
        /// <summary>
        /// 获取背景色画刷实例。
        /// </summary>
        /// <returns></returns>
        private Brush GetBackgroundColorBrushInstance()
        {
            return new SolidColorBrush((Color)ColorConverter.ConvertFromString(this.BackgroundColor));
        }
        #endregion

        #region ProvideValue
        /// <summary>
        /// <see cref="MarkupExtension"/>.ProvideValue方法。
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <returns></returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this.GetBackgroundColorBrushInstance();
        }
        #endregion
    }
}

/*
 * Copyright © 2015 Wang Yucai. All rights reserved.
 */